"""路径工具模块"""

from pathlib import Path
from typing import Optional
from .project_config import ProjectConfig
import argparse

class PathUtils:
    """路径工具类"""

    @staticmethod
    def simplify_path(path: Path) -> str:
        """简化路径显示

        规则：
        1. 如果路径包含 assets/config，只显示 assets/config 之后的部分
        2. 如果路径包含 artifacts/miaoma/tables，只显示 artifacts/miaoma/tables 之后的部分
        3. 如果路径包含 artifacts/test/tables，只显示 artifacts/test/tables 之后的部分
        """
        path_str = str(path)
        if 'assets/config' in path_str:
            return path_str[path_str.index('assets/config'):]
        elif 'artifacts/miaoma/tables' in path_str:
            return path_str[path_str.index('artifacts/miaoma/tables'):]
        elif 'artifacts/test/tables' in path_str:
            return path_str[path_str.index('artifacts/test/tables'):]
        return path_str

    @classmethod
    def get_config_dir(cls, args: argparse.Namespace) -> Path:
        """获取配置目录"""
        config = ProjectConfig.get_instance()
        if config:
            return config.config_dir
        return Path('config')

    @classmethod
    def get_template_dir(cls, args: argparse.Namespace) -> Path:
        """获取模板目录"""
        config = ProjectConfig.get_instance()
        if config:
            return config.template_dir
        return Path('template')

    @classmethod
    def get_tmp_dir(cls, args: argparse.Namespace) -> Path:
        """获取临时目录"""
        config = ProjectConfig.get_instance()
        if config:
            return config.tmp_dir
        return Path('tmp')